public class Solution434 {
    public int countSegments(String s) {
        String[] strings=s.split(" ");
        int ans=0;
        for (String string : strings) {
            if (!string.equals("")){
                ans++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution434().countSegments("Hello, my name is John"));
    }
}
